{
    数据类型
    基本数据类型
    字符串
}

unit learn_unit2;

{$mode ObjFPC}{$H+}

//对外的函数、过程定义
interface

uses
  Classes, SysUtils;

const
  PI :real = 3.14;
var
  age, year :integer;

procedure LearnDataType();

implementation
//实现

procedure LearnDataType();
var
  _integer :Integer = Integer.MaxValue;
  _byte :Byte = Byte.MaxValue;
  _shortint   :Shortint = Shortint.MaxValue;
  _smallint   :Smallint = Smallint.MaxValue;
  _word  :Word = Word.MaxValue;
  _cardinal :Cardinal = Cardinal.MaxValue;
  _longint :Longint = Longint.MaxValue;
  _longword :Longword = Longword.MaxValue;
  _int64 :Int64 = Int64.MaxValue;
  _qword :QWord = QWord.MaxValue;

  _real :Real ;         //默认为double类型
  _single :Single ;
  _double :Double;
  _extended :Extended;
  _comp :Comp;
  _currency :Currency;

  _boolean :Boolean;
  _byteBool :ByteBool;
  _wordBool :WordBool;
  _longBool :LongBool;

  _string :String;
  _shortString :ShortString;
  _ansiString :AnsiString;
  _wideString :WideString;

begin
  age := 30;
  year := 2024;

  Writeln(AnsiToUtf8(Format('Integer类型范围[%d,%d],占%d个字节',[Integer.MinValue, _integer, Integer.Size])));
  Writeln(AnsiToUtf8(Format('Byte类型范围[%d,%d],占%d个字节',[Byte.MinValue, _byte, Byte.Size])));
  Writeln(AnsiToUtf8(Format('Shortint类型范围[%d,%d],占%d个字节',[Shortint.MinValue, _Shortint, Shortint.Size])));
  Writeln(AnsiToUtf8(Format('Smallint类型范围[%d,%d],占%d个字节',[Smallint.MinValue, _Smallint, Smallint.Size])));
  Writeln(AnsiToUtf8(Format('Word类型范围[%d,%d],占%d个字节',[Word.MinValue, _Word, Word.Size])));
  Writeln(AnsiToUtf8(Format('Cardinal类型范围[%d,%d],占%d个字节',[Cardinal.MinValue, _Cardinal, Cardinal.Size])));
  Writeln(AnsiToUtf8(Format('Longint类型范围[%d,%d],占%d个字节',[Low(_Longint), High(_Longint), Longint.Size])));
  Writeln(AnsiToUtf8(Format('Longword类型范围[%d,%d],占%d个字节',[Low(_Longword), High(_Longword), SizeOf(_longword)])));
  Writeln(AnsiToUtf8(Format('Int64类型范围[%d,%d],占%d个字节',[Int64.MinValue, _Int64, Int64.Size])));
  Writeln(AnsiToUtf8(Format('QWord类型范围[%d,%d],占%d个字节',[Low(_qword), High(_qword), QWord.Size])));

  _real := Double.MaxValue;
  Writeln(AnsiToUtf8(Format('Real类型范围[%f,%f],占%d个字节',[Double.MinValue, Double.MaxValue, SizeOf(_real)])));
  Writeln(AnsiToUtf8(Format('Single类型范围[%f,%f],占%d个字节',[Single.MinValue, Single.MaxValue, SizeOf(_single)])));
  Writeln(AnsiToUtf8(Format('Double类型范围[%f,%f],占%d个字节',[Double.MinValue, Double.MaxValue, SizeOf(_double)])));
  //Writeln(AnsiToUtf8(Format('Extended类型范围[%f,%f]',[Low(_extended), High(_extended)])));
  Writeln(AnsiToUtf8(Format('Comp类型范围[%d,%d,占%d个字节]',[Low(_comp), High(_comp), SizeOf(_comp)])));
  Writeln(AnsiToUtf8(Format('Currency类型范围[%f,%f],占%d个字节',[Low(_currency), High(_currency), SizeOf(_currency)])));


  Writeln(AnsiToUtf8(Format('Boolean类型范围[%s,%s],占%d个字节',[Boolean.ToString(Low(_boolean), TUseBoolStrs.True), High(_boolean).ToString(TUseBoolStrs.True), SizeOf(_boolean)])));
  Writeln(AnsiToUtf8(Format('ByteBool类型范围[%s,%s],占%d个字节',
  [ByteBool.ToString(Low(_byteBool), TUseBoolStrs.True),
  ByteBool.ToString(High(_byteBool), TUseBoolStrs.True),
  ByteBool.Size])));
  Writeln(AnsiToUtf8(Format('WordBool类型范围[%s,%s],占%d个字节',  [WordBool.ToString(Low(_wordBool), TUseBoolStrs.True), WordBool.ToString(High(_wordBool), TUseBoolStrs.True), WordBool.Size])));
  Writeln(AnsiToUtf8(Format('LongBool类型范围[%s,%s],占%d个字节',[Low(_longBool).ToString(TUseBoolStrs.True), High(_longBool).ToString(TUseBoolStrs.True), LongBool.Size])));

  _string := _string.PadLeft(1000000, 'c');
  Writeln(AnsiToUtf8(Format('String类型长度%d，无上限',[_string.Length])));

  _shortString := _string;
  Writeln(AnsiToUtf8(Format('ShortString类型最大长度%d字节',[length(_shortString)])));

end;

initialization
//单元初始化
  //windows控制台输入中心需要加入以下2行代码，否则输出为乱码或问号。
  SetMultiByteConversionCodePage(CP_UTF8);
  // SetMultiByteFileSystemCodePage(CP_UTF8); not needed, this is the default under Windows
  SetMultiByteRTLFileSystemCodePage(CP_UTF8);


finalization
//


end.

